import axios from "axios";
import nProgress from "nprogress"; //进度条
import "nprogress/nprogress.css";
import { getTmpId } from "../utils";
// 引入仓库
import store from "@/store";
const request = axios.create({
  baseURL: "/api",
  timeout: 5000,
  headers: {},
}); //前台项目的请求二次封装
request.interceptors.request.use((config) => {
  nProgress.start();
  config.headers.userTempId = getTmpId();
  config.headers.token = localStorage.getItem("token");
  config.headers["token"] = store.state.user.token;

  return config;
});

request.interceptors.response.use(
  (response) => {
    nProgress.done();
    return response.data;
  },
  (message) => {
    console.log(message);
  }
);
export default request;
